package com.vincent.dao;

import com.vincent.common.enums.CacheEnum;
import com.vincent.model.Permission;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Vincent on 2014/12/29.
 */
@Repository("permissionDao")
public class PermissionDao {
    @Resource
    private PermissionMapper permissionMapper;

    @Cacheable(value = CacheEnum.PERMISSIONS)
    public List<Permission> selectAll(){
        return permissionMapper.selectAll();
    }
    @Cacheable(value = CacheEnum.PERMISSIONS)
    public Permission getPermissionByName(String name){
        return permissionMapper.selectByName(name);
    }
    @Cacheable(value = CacheEnum.PERMISSIONS)
    public Permission getPermissionById(Integer id){
        return permissionMapper.selectByPrimaryKey(id);
    }

    public void savePermission(Permission permission){
        permissionMapper.insertSelective(permission);
    }
    public void updatePermission(Permission permission){
        permissionMapper.updateByPrimaryKeySelective(permission);
    }

    public void deletePermission(Integer []id){
        permissionMapper.deletePermission(id);
    }
    @CacheEvict(value = CacheEnum.PERMISSIONS,allEntries = true)
    public void clearCache(){}
}
